﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;

using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Monitoring;
using ScrumTable.DL.Data.Excel.Services;
using ScrumTable.DL.Data.Generic.Cache;

#endregion

namespace ScrumTable.DL.Data.Excel.Cache
{
    /// <summary>
    /// This class is used to load all data below a given project.
    /// </summary>
    internal static class CacheContextUtil
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the internal DataCache attribute name for the stored
        /// DataProvider instance.
        /// </summary>
        private const string DataProviderCacheAttribute = "DataProvider";

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        internal static DataProvider GetDataProvider(this CacheContext context)
        {
            PreCondition.AssertNotNull(context, "context");

            return (context.Attributes[DataProviderCacheAttribute] as DataProvider);
        }

        internal static void SetDataProvider(this CacheContext context, DataProvider provider)
        {
            PreCondition.AssertNotNull(context, "context");

            context.Attributes[DataProviderCacheAttribute] = provider;
        }

        internal static void RemoveDataProvider(this CacheContext context)
        {
            context.Attributes.Remove(DataProviderCacheAttribute);
        }

        #endregion
    }
}